package datasturte.hashmap;

import java.util.ArrayList;
import java.util.List;

/*基于数组实现*/
public class bylist {
    private List<Entry> buckets;

    public bylist() {
        buckets = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            buckets.add(null);
        }
        System.out.println(buckets.size());
    }

    public int hashFunc(int key) {
        int index  = key%100;
        return index;
    }

    @Override
    public String toString() {
        return "bylist{" +
                "buckets=" + buckets +
                '}';
    }

    public static void main(String[] args) {
        bylist bylist = new bylist();
        bylist.put(123, "wby");
        System.out.println(bylist);
    }

    public void put(int key, String value) {
        Entry entry = new Entry(key, value);
        int index = hashFunc(key);
        buckets.set(index, entry);
    }

    public void delete(int key) {
        int index = hashFunc(key);
        buckets.set(index,null);
    }

    class Entry{
        private int key;
        private String value;

        public Entry(int key, String value) {
            this.key = key;
            this.value = value;
        }
    }


}
